package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.TransferForDoingResult;
import com.zhouyibike.uu.utils.TextUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/5/1 0001.
 */
public class MyDanchejiaoyiAdapter extends BaseAdapter {
    private Context context;
    private List<TransferForDoingResult.DataBean> list;

    public MyDanchejiaoyiAdapter(Context context, List<TransferForDoingResult.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<TransferForDoingResult.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.adapter_item, null);
        TextView textView = (TextView) convertView.findViewById(R.id.yihuodongzhuanrangitem_buyinfo);
//        textView.setText(list.get(position));
        textView.setVisibility(View.GONE);
        TextView bikephone = (TextView) convertView.findViewById(R.id.bikephone);
        bikephone.setText(TextUtils.toFormatPhone(list.get(position).getUserName()));
        TextView biketime = (TextView) convertView.findViewById(R.id.biketime);
        biketime.setText(list.get(position).getCreateTime());
        TextView yihuodongzhuanrangitem_isbuy = (TextView) convertView.findViewById(R.id.yihuodongzhuanrangitem_isbuy);
        ImageView dancheyanse = convertView.findViewById(R.id.dancheyanse);
        ImageView yihuodongzhuanrangitem_isbuyicon = convertView.findViewById(R.id.yihuodongzhuanrangitem_isbuyicon);
        if (list.get(position).isIsTransfered()) {
            textView.setBackground(context.getResources().getDrawable(R.drawable.danchejiaoyibuy));
            yihuodongzhuanrangitem_isbuy.setText("转让中");
            yihuodongzhuanrangitem_isbuy.setTextColor(context.getResources().getColor(R.color.colorAccent));
            dancheyanse.setImageDrawable(context.getResources().getDrawable(R.drawable.danchehong));
            yihuodongzhuanrangitem_isbuyicon.setImageDrawable(context.getResources().getDrawable(R.drawable.zhuanrang1));
        } else {
            textView.setBackground(context.getResources().getDrawable(R.drawable.danchejiaoyisell));
            yihuodongzhuanrangitem_isbuy.setText("求购中");
            yihuodongzhuanrangitem_isbuy.setTextColor(context.getResources().getColor(R.color.result_points));
            dancheyanse.setImageDrawable(context.getResources().getDrawable(R.drawable.danchelv));
            yihuodongzhuanrangitem_isbuyicon.setImageDrawable(context.getResources().getDrawable(R.drawable.goumai));
        }
        return convertView;
    }
}
